package org.purpleaf;

import org.springframework.lang.NonNull;

import java.util.Objects;

/**
 * 开放未来应用程序
 * @author 紫叶工作室
 */
public final class OpenMiraiApplication implements Runnable {

    private static volatile OpenMiraiApplication sOpenMiraiApplication;

    @SuppressWarnings({"unused", "all"})
    private final Class<?> mPrimaryType;

    @SuppressWarnings({"unused", "all"})
    private final String[] mPrimaryArgs;

    public OpenMiraiApplication(@NonNull Class<?> primaryType, @NonNull String[] primaryArgs) {
        Objects.requireNonNull(primaryType,
                "Parameter 'primaryType' of constructor 'OpenMiraiApplication' is null.");
        Objects.requireNonNull(primaryArgs,
                "Parameter 'primaryArgs' of constructor 'OpenMiraiApplication' is null.");
        this.mPrimaryType = primaryType;
        this.mPrimaryArgs = primaryArgs;
    }

    public static void run(@NonNull Class<?> primaryType, @NonNull String[] primaryArgs) {
        Objects.requireNonNull(primaryType,
                "Parameter 'primaryType' of method 'OpenMiraiApplication::run' is null.");
        Objects.requireNonNull(primaryArgs,
                "Parameter 'primaryArgs' of method 'OpenMiraiApplication::run' is null.");
        if (Objects.isNull(sOpenMiraiApplication)) {
            synchronized (OpenMiraiApplication.class) {
                if (Objects.isNull(sOpenMiraiApplication)) {
                    sOpenMiraiApplication = new OpenMiraiApplication(primaryType, primaryArgs);
                    sOpenMiraiApplication.run();
                }
            }
        }
    }

    @NonNull
    public Class<?> getPrimaryType() {
        return mPrimaryType;
    }

    @NonNull
    public String[] getPrimaryArgs() {
        return mPrimaryArgs;
    }

    @Override
    public void run() {
    }
}